#!/usr/bin/env python
#===============================================================================
# Copyright 2009 Andrew Coleman
#===============================================================================
# GLWrappers
#
# This module is simply a wrapper over common gl functions I use, in order to be
# able to use them with my custom objects. (Vertex and the like.)
# Though actually you could use these wrappers with any object that has the
# correct attributes.(Object.x, Object.y, etc...)
#
# One requirement for using this behavior is that however you import the OpenGL
# functions, you have to import this module such that it overrides it.
# (Unless you want to use different names for the functions, so they can
# coexist. I've decided to just override for now, since that's the behavior I
# want. Once I distribute, I may pick the latter option, unless I provide a
# complete package so there would be no need for coexistance.)
#
# I'm sick of having to specify overly verbose function calls in my game code,
# that's it! :-)
from OpenGL.GL import glLight as _glLight
from OpenGL.GL import GL_POSITION as _GL_POSITION
from OpenGL.GL import GL_AMBIENT as _GL_AMBIENT
from OpenGL.GLU import gluLookAt as _gluLookAt
from OpenGL.GLU import gluPerspective as _gluPerspective


def glLight(ID, Setting, Object):
    if Setting == _GL_POSITION:
        _glLight(ID, Setting, (Object.x, Object.y, Object.z))
    elif Setting in (_GL_AMBIENT, _GL_DIFFUSE, _GL_SPECULAR):
        _glLight(ID, Setting, (Object.r, Object.g, Object.b, Object.a))

def gluLookAt(Camera):
    _gluLookAt(Camera.x, Camera.y, Camera.z,
                  Camera.focus[0], Camera.focus[1], Camera.focus[2],
                  Camera.up[0], Camera.up[1], Camera.up[2])

def gluPerspective(Perspective):
    _gluPerspective(Perspective.FOVY, Perspective.aspectRatio,
                   Perspective.zNear, Perspective.zFar)
